package com.sdut.material.controller;


import com.sdut.material.pojo.Production;
import com.sdut.material.service.IProductionService;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Controller
@RequestMapping("/production")
public class ProductionController {
    @Autowired
    private IProductionService productionService;
    @RequestMapping("/selectAllProductions")
    @ResponseBody
    public JSONResult selectAllProductions() {
        JSONResult jsonResult = productionService.selectAllProductions();
        return jsonResult;
    }
    @RequestMapping("/getProductionInsertPage")
    public String getProductionInsertPage() {
        return "production/production_insert";
    }
    @RequestMapping("/getProductionListPage")
    public String getProductionListPage() {
        return "production/production_list";
    }
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page,Long limit) {
        return productionService.selectByPage(page,limit);
    }
    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Production production) {
        return productionService.insert(production);
    }
    @RequestMapping("/getProductionUpdatePage")
    public String getProductionUpdatePage() {
        return "production/production_update";
    }
    @RequestMapping("/selectById")
    @ResponseBody
    public JSONResult selectById(Integer productionId) {
        Production production = productionService.selectById(productionId);
        return JSONResult.ok(production);
    }
    @RequestMapping("/update")
    @ResponseBody
    public JSONResult updateProduction(Production production) {
        productionService.updateProduction(production);
        return JSONResult.ok("修改成功");
    }
    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer productionId) {
        productionService.deleteById(productionId);
        return JSONResult.ok("删除成功");
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(String ids) {
        String[] productionIds = ids.split(",");
        for (String id : productionIds) {
            productionService.deleteById(Integer.parseInt(id));
        }
        return JSONResult.ok("删除成功");
    }
}

